﻿<%@ page language="C#" autoeventwireup="true" inherits="GetUsers, MainSite" %>

<input type="checkbox" id="select_all_users" />
<label for="select_all_users">All Users</label>
<div class="wrapper_check">
    <ul id="users_list">
       <%-- <li class="deleted">
            <input type="checkbox" name="u_deleted" id="search_in_deleted_users" />
            <label for="search_in_deleted_users">Include Deleted Users</label>
        </li>--%>
        <%= this.GetUIData() %>
        <%--<li>
            <input type="checkbox" checked id="inputee2_1" class="inputcheckbox" name="u[]" value="134786" />
            <label class="selectbox_label" for="inputee2_1">
                <strong>abcd1</strong>
            </label>
        </li>
        <li>
            <input type="checkbox" checked id="inputee2_2" class="inputcheckbox" name="u[]" value="134749" />
            <label class="selectbox_label" for="inputee2_2">
                <strong>dsfsdfsd</strong>
            </label>
        </li>
        <li>
            <input type="checkbox" checked id="inputee2_3" class="inputcheckbox" name="u[]" value="134746" />
            <label class="selectbox_label" for="inputee2_3">
                <strong>rerewrew</strong>
            </label>
        </li>
        <li>
            <input type="checkbox" checked id="inputee2_4" class="inputcheckbox" name="u[]" value="134748" />
            <label class="selectbox_label" for="inputee2_4">
                <strong>rettfgfgh</strong>
            </label>
        </li>
        <li>
            <input type="checkbox" checked id="inputee2_5" class="inputcheckbox" name="u[]" value="134750" />
            <label class="selectbox_label" for="inputee2_5">
                <strong>sdfsdf23456</strong>
            </label>
        </li>
        <li>
            <input type="checkbox" checked id="inputee2_6" class="inputcheckbox" name="u[]" value="134747" />
            <label class="selectbox_label" for="inputee2_6">
                <strong>sfsfs</strong>
            </label>
        </li>--%>
    </ul>
</div>
<script>

    $(document).ready(function () {
        function listFilter(header, list) {
            input = $("<input>").attr({ "id": "filter_users_text", "class": "filterinput inputnormalwide", "type": "text", "placeholder": "Type to begin filtering..." });
            clear = $("<span>").text(" clear").attr({ "id": "clear_users_filter", "style": "cursor:pointer" });

            $(input).insertBefore(header);
            $(clear).insertBefore(header);
            $("<br/>").insertBefore(header);


            $(clear).hide();

            $(input).change(function () {

                if ($(input).val().length > 0) {
                    $(clear).show();
                }
                else {
                    $(clear).hide();
                }

                var filter = $(this).val().toLowerCase();
                if (filter) {
                    $(list).find("label").each(function () {
                        if ($(this).text().toLowerCase().indexOf(filter) === -1 && !($(this).parent().hasClass("deleted"))) {
                            $(this).parent().slideUp();
                        } else if ($(this).text().toLowerCase().indexOf(filter) !== -1 && !($(this).parent().hasClass("deleted"))) {
                            $(this).parent().slideDown();
                        }
                    });
                } else {
                    $(list).find("label:not(:empty)").parent().slideDown();
                    if ($("#users_list>li>input:[id^='inputee']:not(:checked)").length > 0) {
                        $("#select_all_users").attr('checked', false);
                    } else {
                        $("#select_all_users").attr('checked', true);
                    }
                }
                return false;
            })
            .keyup(function () {
                $(this).change();
            });
        }
        listFilter($("#select_all_users"), $("#users_list"));
        $("#clear_users_filter").click(function (event) {
            $('#filter_users_text').val('');
            $('#filter_users_text').change();
        });

    });
    $("#select_all_users").live("change", function (event) {

        // This was added because the 'All type' checkbox wasn't having its checked attribute removed properly
        $(this).attr("checked", $(this).attr("checked") ? true : false);

        $($("#users_list>li>input:[id^='inputee']").filter(':visible')).attr('checked', $(this).is(':checked')).next().css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
    });

    $("#select_all_users").attr('checked', true);

    $('input:[id^="inputee"]').live("change", function (event) {
        var unchecked_present = true;
        $('input:[id^="inputee"]').each(function (i) {

            if (!$(this).is(':checked')) {
                unchecked_present = false;
            }

        });
        $("#select_all_users").attr('checked', unchecked_present);
        $(this).next().css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
    });





</script>
